/*
@Author   : Uyynot
@Email    : uyynot@qq.com
@Time     : 2023/10/25 14:17
@File     : response.go
@Project  : GoProject
@Desc     :
*/
package response

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type Response struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data any    `json:"data"`
}

func Fail(ctx *gin.Context, httpCode int, err error, data any) {
	resp := Response{
		Code: errorCodeMap[err],
		Msg:  err.Error(),
		Data: data,
	}
	ctx.JSON(httpCode, resp)
}

func Success(ctx *gin.Context, data any) {
	resp := Response{
		Code: errorCodeMap[ErrSuccess],
		Msg:  ErrSuccess.Error(),
		Data: data,
	}
	ctx.JSON(http.StatusOK, resp)
}
